package com.kingwood.algorithm.test;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author 22025812
 * @Description: 绘图机器
 * https://fcqian.blog.csdn.net/article/details/127240714
 * @Date: 2024/3/28 9:53
 * @Modified By：
 * @Version 1.0
 */
public class HuituJiqi {
    public static int getResult(int[][] arr, int endX) {
        int area = 0;
        int last_x = 0;
        int last_y = 0;

        for (int i=0; i<arr.length; i++) {
            int cur_x = arr[i][0];
            int offset_y = arr[i][1];

            area += (cur_x - last_x) * Math.abs(last_y);

            last_x = cur_x;
            last_y += offset_y;
        }

        if (last_x < endX) {
            area += (endX - last_x) * Math.abs(last_y);
        }

        return area;
    }

    public static int getResult2(int[][] arr, int endX) {
        int area = 0;
        int last_x = arr[0][0];
        int last_y = arr[0][1];

        for (int i=1; i<arr.length; i++) {
            int cur_x = arr[i][0];
            int offset_y = arr[i][1];

            area += (cur_x - last_x) * Math.abs(last_y);

            last_x = cur_x;
            last_y += offset_y;
        }

        if (last_x < endX) {
            area += (endX - last_x) * Math.abs(last_y);
        }

        return area;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] paramArr = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        int n = paramArr[0];
        int endX = paramArr[1];
        int[][] arr = new int[n][2];

        for (int i=0; i<n; i++) {
            int[] item = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            arr[i] = item;
        }

        System.out.println(getResult(arr, endX));

        System.out.println(getResult2(arr, endX));
    }
}
